package com;

import java.sql.Timestamp;
import java.util.Iterator;
import java.util.List;



import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.ProjectionList;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Property;
import org.hibernate.criterion.Restrictions;

import com.google.gson.Gson;


public class os
{
	public static void main(String s[])
	{
		System.out.println("logic");
		SessionFactory s1=new Configuration().configure("/hibernate.cfg.xml").buildSessionFactory();
		Session session=s1.openSession();
		//select os.osname id.name from machine id, osvo so
		Criteria criteria = session.createCriteria(osvo.class, "os");
		criteria.createAlias("os.machineid", "id", Criteria.INNER_JOIN);
		
		ProjectionList p=Projections.projectionList();
		
		p.add(Projections.property("id.name"));
		p.add(Projections.property("osname"));
		criteria.setProjection(p);
		List l1 =  criteria.list();
		Gson gson = new Gson();
         String record = gson.toJson(l1);
         System.out.println("record in json = " + record);
         
         
         
         
         
         

		
		session.close();
		s1.close();
		
	}
}









